#ifndef DATABASE_DATABASE_H
#define DATABASE_DATABASE_H 1

#include <common/macro/build.h>
#include <table/table.h>
#include <storage/storage.h>
#include <transaction/abortlog.h>
#include <transaction/transactionlog.h>

typedef struct table_storage_t {
	table_t *table;
	storage_t *storage;
} table_storage_t;

typedef struct database_t {
	const char *basedir;

	table_storage_t *tables;
	int tables_c;

	/* There are for entire database. */
	struct transaction_log_t *transaction_log;
	struct abort_log_t *abort_log;
} database_t;

API_PUBLIC database_t *database_open(const char *);
API_PUBLIC void database_close(database_t *);
API_PUBLIC int database_table_create(database_t *, table_t *);
API_PUBLIC int database_table_drop(database_t *, const char *);
API_PUBLIC int database_table_open(database_t *, const char *, table_storage_t *);
API_PUBLIC table_t *database_table_get(database_t *, const char *);
API_LIBLOCAL int database_table_open_all(database_t *);
API_LIBLOCAL int database_fsync_data(database_t *);

#endif
